package com.autotest.nore.mapper;

import com.autotest.nore.domain.Api;
import com.autotest.nore.dto.ApiDTO;
import com.autotest.nore.dto.ApiListDTO;
import com.autotest.nore.request.QueryRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ApiMapper {
    void addApi(Api api);

    void updateApi(Api api);

    void deleteApi(String id);

    ApiDTO getApiDetail(String id);

    List<ApiDTO> getApiList(QueryRequest request);


    @Select("SELECT id,name,method FROM api WHERE module_id = #{moduleId} and status='Normal'")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "method", column = "method"),
            @Result(property = "caseApiList", column = "id", javaType = List.class, many = @Many(select = "com.autotest.nore.mapper.CaseApiMapper.getCaseApisByApiId"))
    })
    List<ApiListDTO> getApisByModuleId(@Param("moduleId") String moduleId);


    Api findByPathAndMethod(@Param("path") String path, @Param("method") String method);


    Api findByPathMethodAndModulePrefix(@Param("path") String path,
                                        @Param("method") String method,
                                        @Param("modulePrefix") String modulePrefix);


}